package com.qidian.controller;

import com.qidian.pojo.QdPost;
import com.qidian.service.QdPostService;
import com.qidian.util.LayuiDataList;
import com.qidian.util.QidianResponse;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.annotation.Resource;

/**
 * (QdPost)控制层
 *
 * @author 戴着假发的程序员
 * @since 2022-02-27 11:05:06
 */
@RestController
@RequestMapping("/qdPost")
public class QdPostController {
    /**
     * 服务对象
     */
    @Resource
    private QdPostService qdPostService;

    /**
     * 通过主键查询单条数据
     * @param postId
     * @return 单条数据
     */
    @RequestMapping(value = "get", method = RequestMethod.GET)
    public QidianResponse selectOne(Long postId) {
        return qdPostService.selectById(postId);
    }
    
    /**
     * 新增一条数据
     * @param qdPost 实体类
     * @return QidianResponse
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public QidianResponse insert(QdPost qdPost) {
        return qdPostService.insert(qdPost);
    }

    /**
     * 修改一条数据
     * @param qdPost 实体类
     * @return QidianResponse
     */
    @RequestMapping(value = "update")
    public QidianResponse update(QdPost qdPost) {
        return qdPostService.update(qdPost);
    }

    /**
     * 删除一条数据
     *
     * @param qdPost 参数对象
     * @return Response对象
     */
    @RequestMapping(value = "delete")
    public Map delete(QdPost qdPost) {
        Map map = new HashMap();
        map.put("code",200);
        int result = qdPostService.deleteById(qdPost.getPostId());
        if (result <= 0) {
           map.put("code",500);
        }
        return map;
    }

     /**
     * 批量删除
     *
     * @param ids
     * @return Response对象
     */
    @RequestMapping(value = "deletes")
    public Map deletes(Long [] ids) {
        Map map = new HashMap();
        map.put("code",200);
        int result = qdPostService.deleteByIds(ids);
        if (result <= 0) {
           map.put("code",500);
        }
        return map;
    }

    /**
     * 查询全部
     *
     * @return Response对象
     */
    @RequestMapping(value = "selectAll")
    public QidianResponse selectAll() {
        return qdPostService.selectAll();
    }

    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return List<QdPost>
     */
    @RequestMapping(value = "selectPage", method = RequestMethod.GET)
    public List<QdPost> selectPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit) {
        return qdPostService.selectPage(page, limit);
    }
    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return List<QdPost>
     */
    @RequestMapping(value = "selectPageByPojo", method = RequestMethod.GET)
    public List<QdPost> selectPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit,QdPost qdPost) {
        return qdPostService.selectPage(page, limit,qdPost);
    }

        /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return Response对象
     */
    @RequestMapping(value = "selectPageForLayui")
    public LayuiDataList<QdPost> selectPageForLayui(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit, String postName) {
        return qdPostService.selectPageForLayui(page, limit,postName);
    }

    
}